package com.gf.framework.rediscachedemo.controller;

import com.gf.framework.redis.annotation.RedissonLock;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author gaofei
 * @Description
 * @create 2022/5/24 16:01
 */
@RestController
@Api(tags = "分布式锁测试")
public class RedissonLockTestController {
    @GetMapping("locktest1")
    // 使用redisson做分布式锁
    @RedissonLock(value = "locktest")
    public String locktest() throws InterruptedException {
        Thread.sleep(1000 * 5);
        return "true";
    }

    // 两个接口一起调用，另外一个尝试1秒后会抛出去异常
    @GetMapping("locktest2")
    // 使用redisson做分布式锁
    @RedissonLock(value = "locktest", lockKey = "")
    public String locktest2() throws InterruptedException {
        Thread.sleep(1000 * 5);
        return "true";
    }
}
